package com.org.gameloft.GLIDER.IDE;

import com.org.gameloft.GLIDER.common.GLLogger;
import com.org.gameloft.GLIDER.common.GLIDEROptions;
import com.org.gameloft.GLIDER.util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.Method;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Aug 1, 2007
 * Time: 11:54:25 AM
 * Revision: 0
 */
public class GLIDERMain extends JWindow
{
    private static GLIDERMain splashWindow;
    private boolean showAbout;

    public GLIDERMain(boolean showAbout)
    {
        this.showAbout = showAbout;
        setSize(600, 300);
        JLabel lbl = new JLabel(new ImageIcon("res/splash.jpg"));
        getContentPane().add(lbl, BorderLayout.CENTER);
        pack();
        Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension imgSize = lbl.getPreferredSize();
        setLocation((scrSize.width - imgSize.width) / 2, (scrSize.height - imgSize.height) / 2);
        setVisible(true);

        if (showAbout)
        {
            addMouseListener(new MouseAdapter()
            {

                public void mouseClicked(MouseEvent e)
                {
                    hideSplash();
                }
            });
        }
    }

    public static void showSplash()
    {
        showSplash(false);
    }

    public static void showSplash(boolean showAbout)
    {
        splashWindow = new GLIDERMain(showAbout);
    }

    public static void hideSplash()
    {
        splashWindow.setVisible(false);
        splashWindow.dispose();
        splashWindow = null;
    }

    public static void main(String[] args)
    {
        Util.getAppFolder();
        showSplash();
        GLIDEROptions.load();
        try
        {
            Method method = Class.forName("com.org.gameloft.GLIDER.IDE.GLIDERWindow").getMethod("create", null);
            method.invoke(null, null);
        }
        catch (Exception e)
        {
            GLLogger.log(e);
        }
    }
}
